package com.example.ruiji.controller.tag;

import com.alibaba.fastjson.JSONArray;
import com.example.ruiji.dao.mapper.LtagMapper;
import com.example.ruiji.service.TagService.TagServiceImpl;
import com.example.ruiji.service.article.ArticleServiceImpl;
import com.example.ruiji.utils.dos.LtagDo;
import com.example.ruiji.utils.vo.Result;
import com.example.ruiji.utils.vo.param.PageParam;
import com.example.ruiji.utils.vo.param.TagVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Author:BaiYiChen
 * Date:2022/4/20 20:34
 *
 * @author BaiYiChen
 */
@RestController
@RequestMapping(value = "/tags",produces = "application/json;charset=utf-8")
public class TagsController {
  @Autowired
  private TagServiceImpl tagService;
  @Autowired
  private LtagMapper ltagMapper;
  @Autowired
  private ArticleServiceImpl articleService;
  @GetMapping("/hot")
  public Result hotTags(){
    int hotTag=5;
    List<TagVo> hotTags = tagService.getHotTags(hotTag);
    return Result.successful(hotTags);
  }
  
  @GetMapping("/tag")
  public List tags(HttpServletResponse res){
    /**设置响应头允许ajax跨域访问**/
    res.setHeader("Access-Control-Allow-Origin","*");
    /*星号表示所有的异域请求都可以接受，*/
    res.setHeader("Access-Control-Allow-Methods","GET,POST");
    List<LtagDo> ltagDos = ltagMapper.findAll();
    return ltagDos;
  }
  @PostMapping("/cnt")
  public Result articleCountByTags(@RequestParam("tId")Integer id){
    Long aLong = articleService.listArticleCountByTag(id);
    return Result.successful(aLong);
  }
  @PostMapping("/showCategory")
  public Result showCategoryByTag(@RequestParam("tId")Integer id, PageParam param){
    return articleService.listArticleByTag(id, param);
  }
}
